import concurrent.futures
import glob
import logging
import math
import os
from datetime import datetime, timedelta
from pathlib import Path
import ddddocr
import pandas as pd
import pytest
from tools.login聚水潭 import login_聚水潭
from tools.上传至erp import 上传ERP
from tools.合并excel import merge_excel_files

should_skip_all = False


def pytest_runtest_makereport(item, call):
    global should_skip_all
    if call.when == 'call' and call.excinfo is not None:
        should_skip_all = True


def pytest_runtest_setup(item):
    if should_skip_all:
        pytest.skip("Skipping due to previous test failure")


@pytest.fixture
def username():
    return get_username()


@pytest.fixture(scope="function", autouse=False, name='date')
def get_date():
    date = (datetime.now() - timedelta(days=1)).strftime("%Y-%m-%d")
    # date = (datetime.now() - timedelta(days=7)).strftime("%Y-%m-%d")
    # date = '2024-03-31'
    return date


@pytest.fixture(scope="function", autouse=False, name='date_start')
def get_date_start():
    date_start_ = (datetime.now() - timedelta(days=2)).strftime("%Y-%m-%d")
    # date_start_ = '2024-03-16'
    return date_start_


def get_username():
    df = pd.read_excel("./淘系账号密码.xlsx")
    num = math.ceil(len(df) / 4)
    for i in range(1, num + 1):
        start = (i - 1) * 4
        end = i * 4
        if i == num:
            yield df[start:]
        else:
            yield df[start:end]
